草庐IT

ASP.NET Web Forms - 母版页

全部标签

c# - 使用 asp.net 发送邮件以及嵌入的图像

使用asp.net发送带有嵌入图像的邮件我已经用过following,但是没用DimEMAsSystem.Net.Mail.MailMessage=NewSystem.Net.Mail.MailMessage(txtFrom.Text,txtTo.Text)DimAAsSystem.Net.Mail.Attachment=NewSystem.Net.Mail.Attachment(txtImagePath.Text)DimRGenAsRandom=NewRandom()A.ContentId=RGen.Next(100000,9999999).ToString()EM.Attachme

c# - 在 ASP.NET MVC 中的 ViewModel 类上使用 Bind 属性

为什么开发人员可能会在ASP.NETMVC项目中对ViewModel对象使用Bind属性,这会对应用程序产生不利影响吗?[Bind(Include="Id,Name")][MetadataType(typeof(MyViewModelValidation))]publicclassMyViewModel{publicstringCustomerProductUserName{get;set;}[Display(Name="Name")]publicstringName{get;set;}}publicclassMyViewModelValidation{[HiddenInput(Dis

c# - 将查询参数绑定(bind)到 ASP.NET Core 中的模型

我正在尝试使用从查询参数到搜索对象的模型绑定(bind)。我的搜索对象是[DataContract]publicclassCriteria{[DataMember(Name="first_name")]publicstringFirstName{get;set;}}我的Controller有以下Action[Route("users")]publicclassUserController:Controller{[HttpGet("search")]publicIActionResultSearch([FromQuery]Criteriacriteria){...}}当我按如下方式调用端

c# - 如何为 ASP.NET Core 中的单元/集成测试模拟 IFormFile?

我想编写用于在ASP.NETCore中上传文件的测试,但似乎找不到一种很好的方法来模拟/实例化从IFormFile派生的对象。关于如何做到这一点有什么建议吗? 最佳答案 假设你有一个Controller,比如......publicclassMyController:Controller{publicTaskUploadSingle(IFormFilefile){...}}...使用被测方法访问IFormFile.OpenReadStream()。从ASP.NETCore3.0开始,使用FormFileClass的实例现在是IFor

c# - ASP.NET MVC 4,EF5,模型中的唯一属性 - 最佳实践?

ASP.NETMVC4、EF5、代码优先、SQLServer2012Express在模型中实现唯一值的最佳做法是什么?我有一个places类,它有一个“url”属性,每个地方都应该是唯一的。publicclassPlace{[ScaffoldColumn(false)]publicvirtualintPlaceID{get;set;}[DisplayName("DateAdded")]publicvirtualDateTimeDateAdded{get;set;}[Required(ErrorMessage="PlaceNameisrequired")][StringLength(10

c# - 我的 Asp.Net C# 类如何返回 json 格式

如何想要一个返回json格式的类。这个方法在Controller中很有效但是当我想放入一个类时,Json对象似乎不存在。publicJsonResultTest(){//Error1Thename'Json'doesnotexistinthecurrentcontextC:\inetpub\wwwroot\mvcinfosite\mvcinfosite\Validation\ValidationClass\BaseValidator.cs6620mvcinfositereturnJson(new{errMsg="test"});}我想将该代码放在一个简单的类中。我希望能够在许多Cont

c# - ASP.NET Identity 2.0 检查当前用户是否在角色 IsInRole

使用ASP.NETIdentity2.0如何检查当前登录的用户是否在某个角色中?我正在使用以下内容,但想知道是否有更有效的方法。varum=newUserManager(newUserStore(newDbContext()));varau=um.FindByEmail(Context.User.Identity.GetUserName());varinrole=um.IsInRole(au.Id,"Admin");if(inrole){} 最佳答案 ASPIdentity中的正确方法很简单User.IsInRole("rolena

c# - 如何更改 URL 中的 ASP.NET MVC Controller 名称?

如果我们有"example_name",我们可以使用[ActionName("")]在url中更改它所以,我想为Controller名称执行此操作。我能做到:ControllerName>example_nameController>在URL中:"/example_controller"我想在URL中像这样更改Controller名称:"/example-conroller" 最佳答案 您需要使用AttributeRouting,MVC5中引入的功能。根据您的示例,您应该按如下方式编辑您的Controller:[RoutePrefi

c# - 自定义 ASP.NET MVC ActionFilterAttribute - 永远不会调用 Hook

您好,我正在尝试做一些看起来很简单的事情,并且以这种方式进行了记录,但由于某种原因,它并没有那么容易。基本上我是这样写的:publicclassCacheControllAttribute:ActionFilterAttribute{publicoverridevoidOnResultExecuting(ResultExecutingContextfilterContext){//dosomethingbase.OnResultExecuting(filterContext);}}然而,当我尝试在这样的操作结果上使用它时:[CacheControllAttribute]publicAc

c# - 在 ASP.NET MVC Core 应用程序 (RC2) 中显示项目版本

如何显示project.json中的应用程序版本?我正在使用gulp-bump来自动增加版本,但我无法显示最新版本。这是我正在尝试的:@(Microsoft.Extensions.PlatformAbstractions.PlatformServices.Default.Application.ApplicationVersion)这不起作用,它显示“1.0.0”而不是来自project.json的实际值我也试过了,但看起来它在RC2中不再有效:@injectMicrosoft.Extensions.PlatformAbstractions.IApplicationEnvironmen